package com.yanqu.road.server.manger.maidian.innroom;

import com.yanqu.road.entity.config.inn.DishesInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.inn.UserDishes;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.inn.InnModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.config.DishesMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class InnRoomLog {

    public static final String INN_ROOM = "inn_room";
    public static final String INN_GODMENU = "inn_godmenu";
    public static final String VOCATION = "vocation";
    public static final String INN_MENU = "inn_menu";
    public static final String INN_LV = "inn_lv";

    public static void uploadSnapshot(GamePlayer player) {

        try {
            if (!DataAnalyticsMgr.openDataAnalytics()) return;

            DefaultEventTraceAction action = new DefaultEventTraceAction(INN_ROOM, player);

            InnModule innModule = player.getModule(InnModule.class);

            List<Map<String, Object>> objectGroup = new ArrayList<>();

            for (Map.Entry<Integer, UserDishes> dishesEntry : innModule.getUserDishesMap().entrySet()) {
                UserDishes userDishes = dishesEntry.getValue();
                Map<String, Object> map = new HashMap<>();
                DishesInfo dishes = DishesMgr.getDishes(userDishes.getDishesId());
                if(dishes != null){
                    SkillInfo skillInfo = SkillMgr.getSkillInfo(dishes.getSkillId());
                    if(skillInfo != null) {
                        map.put(VOCATION, skillInfo.getParamList().get(2));
                    }
                }
                map.put(INN_MENU, userDishes.getDishesId());
                map.put(INN_LV, userDishes.getLevel());
                objectGroup.add(map);
            }
            if(objectGroup.size() == 0){
                return;
            }
            action.build(INN_GODMENU, objectGroup);

            action.trace();
        } catch (Exception e) {
            DataAnalyticsMgr.getLogger().error(" error ", e);
        }

    }
}
